/*
 * @Description:
 * @Version: 1.0
 * @Autor: chen_yt
 * @Date: 2022-06-10 09:17:23
 * @LastEditors: chen_yt
 * @LastEditTime: 2022-08-01 09:51:26
 */
import request from '@/utils/request'
import store from '@/store'

import { getSaasLimitClientConfigInMain } from '@/saas/clientLimit'

export function initTenant(data) {
    let limitData = getSaasLimitClientConfigInMain(data)
    return request({
        url: '/sys-system/tenant/init',
        method: 'post',
        data: limitData,
        headers: {
            'Content-Type': 'application/json;charset=UTF-8'
        }
    })
}

/** 获取菜单树 */
export function getMenusTree() {
    return request({
        url: '/sys-system/menus/tree',
        method: 'get',
        params: {
            portalId: store.state.portal.id,
            type: 1
        }
    })
}

export function getTenant(id) {
    return request({
        url: '/sys-system/tenant',
        method: 'get',
        params: {
            id
        }
    })
}

export function getClient(id) {
    return request({
        url: '/sys-system/client',
        method: 'get',
        params: {
            id
        }
    })
}

export function getRoleInOtherTenantByCode(code, tenantConfig) {
    return request({
        url: '/sys-system/role',
        method: 'get',
        params: {
            code
        },
        tenantConfig
    })
}

export function getRoleUsersInOtherTenant(params, tenantConfig) {
    return request({
        url: '/sys-user/role/users/page',
        method: 'get',
        params: {
            ...params
        },
        tenantConfig
    })
}

export function addRoleUsersInOtherTenant(data, tenantConfig) {
    return request({
        url: '/sys-system/role/users',
        method: 'POST',
        data: data,
        tenantConfig
    })
}

export function deleteRoleUsersInOtherTenant(data, tenantConfig) {
    return request({
        url: '/sys-system/role/users',
        method: 'delete',
        data: data,
        tenantConfig
    })
}